﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using SUT = Admx_Generator;

namespace Admx_Generator.Tests
{
    public class Test_Namespace
    {
        [TestClass]
        public class Creator_Should
        {
            [TestMethod]
            public void ProperlyInitializeTargetAndPrefix_WhenCalledWithATargetAndAPrefix()
            {
                // Arrange
                string expectedTarget = "EasyCompany.Policies.PstBackup2013";
                string expectedPrefix = "PstBackup";
                SUT.Namespace expectedNamespace = new SUT.Namespace(expectedTarget, expectedPrefix);

                // Assert
                Assert.AreEqual(expectedTarget, expectedNamespace.Target);
                Assert.AreEqual(expectedPrefix, expectedNamespace.Prefix);
            }

            [TestMethod]
            public void ProperlyInitializeTargetAndPrefix_WhenCalledWithATargetAndNoPrefix()
            {
                // Arrange
                string expectedTarget = "EasyCompany.Policies.PstBackup2013";
                string expectedPrefix = "PstBackup2013";
                SUT.Namespace expectedNamespace = new SUT.Namespace(expectedTarget, string.Empty);

                // Assert
                Assert.AreEqual(expectedTarget, expectedNamespace.Target);
                Assert.AreEqual(expectedPrefix, expectedNamespace.Prefix);
            }

            [TestMethod]
            public void ProperlyInitializeTargetAndPrefix_WhenCalledWithATargetAndPrefixIsNull()
            {
                // Arrange
                string expectedTarget = "EasyCompany.Policies.PstBackup2013";
                string expectedPrefix = "PstBackup2013";
                SUT.Namespace expectedNamespace = new SUT.Namespace(expectedTarget, null);

                // Assert
                Assert.AreEqual(expectedTarget, expectedNamespace.Target);
                Assert.AreEqual(expectedPrefix, expectedNamespace.Prefix);
            }

            [TestMethod]
            public void ProperlyInitializeTargetAndPrefix_WhenCalledWithAFilename()
            {
                // Arrange
                string expectedTarget = "Microsoft.Policies.Auditing";
                string expectedPrefix = "auditing";
                SUT.Namespace expectedNamespace = new SUT.Namespace(@"C:\Users\Courtel.MCSA\Documents\Visual Studio 2013\Projects\Admx Generator\Tests_Admx Generator\Test Files\Namespace\AuditSettings.admx");

                // Assert
                Assert.AreEqual(expectedTarget, expectedNamespace.Target);
                Assert.AreEqual(expectedPrefix, expectedNamespace.Prefix);
            }
        }

        [TestClass]
        public class Equals_Should
        {
            [TestMethod]
            public void ReturnsTrue_WhenTargetsAreEqualsAndPrefixAreEquals()
            {
                // Arrange
                SUT.Namespace namespace1 = new SUT.Namespace("EasyCompany.Policies.PstBackup2013", "PstBackup2013");
                SUT.Namespace namespace2 = new SUT.Namespace("EasyCompany.Policies.PstBackup2013", "PstBackup2013");

                // Assert
                Assert.IsTrue(namespace1.Equals(namespace2));
            }
            [TestMethod]
            public void ReturnsTrue_WhenTargetsAreEqualsAndPrefixAreDifferents()
            {
                // Arrange
                SUT.Namespace namespace1 = new SUT.Namespace("EasyCompany.Policies.PstBackup2013", "PstBackup2013");
                SUT.Namespace namespace2 = new SUT.Namespace("EasyCompany.Policies.PstBackup2013", "PstBackup2016");

                // Assert
                Assert.IsTrue(namespace1.Equals(namespace2));
            }

            [TestMethod]
            public void ReturnsFalse_WhenTargetsAreDifferentsAndPrefixAreEquals()
            {
                // Arrange
                SUT.Namespace namespace1 = new SUT.Namespace("EasyCompany.Policies.PstBackup2013", "PstBackup2013");
                SUT.Namespace namespace2 = new SUT.Namespace("EasyCompany.Policies.PstBackup2016", "PstBackup2013");

                // Assert
                Assert.IsFalse(namespace1.Equals(namespace2));
            }

            [TestMethod]
            public void ReturnsFalse_WhenTargetsAreDifferentsAndPrefixAreDifferents()
            {
                // Arrange
                SUT.Namespace namespace1 = new SUT.Namespace("EasyCompany.Policies.PstBackup2013", "PstBackup2013");
                SUT.Namespace namespace2 = new SUT.Namespace("EasyCompany.Policies.PstBackup2016", "PstBackup2016");

                // Assert
                Assert.IsFalse(namespace1.Equals(namespace2));
            }            
        }
    }
}
